package com.cyy.springbootinit.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import com.cyy.springbootinit.model.vo.WaterFeeRuleResponseVo;
import com.cyy.springbootinit.service.WaterFeeRuleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class WaterFeeRuleServiceImpl implements WaterFeeRuleService {

    private final KieContainer kieContainer;

    @Override
    public WaterFeeRuleResponseVo calculateOrderFee(Double count) {
        System.out.println("count"+count);
        KieSession kieSession = kieContainer.newKieSession();

        //封装返回对象
        WaterFeeRuleResponseVo waterFeeRuleResponseVo = new WaterFeeRuleResponseVo();
        kieSession.setGlobal("waterFeeRuleResponseVo", waterFeeRuleResponseVo);
        // 设置订单对象
        kieSession.insert(count);
        // 触发规则
        kieSession.fireAllRules();
        // 中止会话
        kieSession.dispose();
        log.info("计算结果：{}",waterFeeRuleResponseVo.getTotalAmount() );
        System.out.println("计算结果：{}"+waterFeeRuleResponseVo.getTotalAmount());
        //封装返回对象
        return waterFeeRuleResponseVo;
    }
}
